package com.thread.thread;

import org.springframework.boot.test.context.SpringBootTest;

/**
 * Java实现多线程的方式1
 * 继承Thread类，重写run方法
 */
@SpringBootTest
public class StartThread extends Thread{
    @Override
    public void run(){
        //此处为thread执行的任务内容
        for (int i = 0; i < 200; i++) {
            System.out.println("多线程测试"+i+"："+currentThread().getName());
        }
    }

    public static void main(String[] args) {
        StartThread st = new StartThread();
        System.out.println("线程状态："+st.getName()+st.getState());
        //调用start方法启动多线程
        st.start();
        System.out.println("线程状态："+st.getName()+st.getState());
        for (int i = 0; i < 1000; i++) {
            System.out.println("主线程测试"+i+"："+currentThread().getName()+currentThread().getState());
        }
        System.out.println("线程状态："+st.getName()+st.getState());
    }
}
